package com.bluetooth.phone;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelStore;
import androidx.lifecycle.ViewModelStoreOwner;


public class BluetoothPhoneApp extends Application implements ViewModelStoreOwner {

    private static final String TAG = "BluetoothPhoneApp";

    private static volatile BluetoothPhoneApp INSTANCE;

    private ViewModelStore viewModelStore;

    /**
     * 获取全局的Application
     *
     * @return BaseApp
     * @author yangqiang
     * @date 2022/2/25 16:34
     */
    public static BluetoothPhoneApp getApp() {
        return INSTANCE;
    }

    /**
     * 获取Application的Context
     *
     * @return Context
     * @author yangqiang
     * @date 2022/2/25 16:36
     */
    public static Context getContext() {
        return INSTANCE.getApplicationContext();
    }

    @Override
    public void onCreate() {
        super.onCreate();
//        Log.d(TAG, "onCreate");
//        INSTANCE = this;
//
//        EngineManager.startInit();
//
//        LogConfig.init();
//
//        CommUtils.init(this, HandlerStaticInstance.newInstanceMainLooper(null), android.os.Process.myTid());
//
//        DarkModeUtils.init(this);
////        startSyncService();
//        MMKV.initialize(this);
//        //SendContractManager.init(this);
//        PbapManager.getInstance().init(this);
//        LiveEventBus.config().enableLogger(true);
//        BroadCastManager.INSTANCE.startListening();
//        BroadCastManager.INSTANCE.registerCallReceiver();
//
//        viewModelStore = new ViewModelStore();
    }

    private void startSyncService() {
        Log.d(TAG, "startSyncService");
        Intent service = new Intent();
        service.setAction("com.hsae.bluetooth.phone.sync.data");
        service.setPackage(getPackageName());
        startService(service);
        Log.d(TAG, "startSyncService end");
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }


    @NonNull
    @Override
    public ViewModelStore getViewModelStore() {
        return viewModelStore;
    }
}